<%@page pageEncoding="UTF-8" language="java" contentType="text/html;UTF-8" %>

<a href="javascript:void(0);" id="testSave">测试保存</a><br/>
<a href="javascript:void(0);" id="testPut">测试PUT提交</a><br/>
<a href="javascript:void(0);" id="testDelete">测试DELETE提交</a><br/>

<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>

<script type="text/javascript">

    $(function () {
        $("#testSave").click(function(){
            $.ajax({
                contentType:"application/json",
                type:"POST",
                url:"/user/save",
                data:'{"name":"Jocktesfssdfsd","age":"20"}',
                dataType:"text",
                //回调函数
                success:function(data){
                    console.log(data);
                    alert(data);
                }
            });
        });
    });

    $(function () {
        $("#testPut").click(function(){
            $.ajax({
                type:"PUT",
                url:"/user/1",
                //回调函数
                success:function(data){
                    alert(data);
                }
            });
        });

        $("#testDelete").click(function(){
            $.ajax({
                type:"POST",
                url:"/user/2",
                //回调函数
                success:function(data){
                    alert(data);
                }
            });
        });
    });
</script>